package com.fy.controller;

import com.fy.utils.result.PageResult;
import com.fy.utils.result.Result;
import lombok.extern.slf4j.Slf4j;
import com.fy.common.constants.Constants;
import com.fy.common.annotation.GlobalInterceptor;
import com.fy.pojo.dto.file.RecycleFileDTO;
import com.fy.pojo.vo.user.LoginUserVO;
import com.fy.service.RecycleFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/recycle")
public class RecycleController {

    @Autowired
    private RecycleFileService recycleFileService;

    /**回收站文件分页查询
     *
     * @param recycleFileDTO
     * @return
     */
    @PostMapping("/loadRecycleList")
    @GlobalInterceptor
    public Result loadRecycleList(RecycleFileDTO recycleFileDTO, HttpSession httpSession){
        LoginUserVO loginUserVO= (LoginUserVO) httpSession.getAttribute(Constants.SESSION_KEY);

        log.info("recycleFileDTO:{}",recycleFileDTO);
        PageResult pageResult=recycleFileService.loadRecycleList(recycleFileDTO,loginUserVO);
        log.info("返回的回收站数据为:{}",pageResult);
        return Result.success(pageResult);
    }

    /**恢复删除文件
     *
     * @param fileIdList
     * @return
     */
    @PostMapping("/recoverFile")
    @GlobalInterceptor
    public Result recoverFile(@RequestParam("fileIds") List<String> fileIdList){
        log.info("恢复删除fileIds:{}",fileIdList);
        recycleFileService.recoverFile(fileIdList);
        return Result.success();
    }

    /**永久删除回收站文件
     *
     * @param delFileList
     * @return
     */
    @PostMapping("/delFile")
    @GlobalInterceptor
    public Result delFile(@RequestParam("fileIds") List<String> delFileList,HttpSession httpSession){
        LoginUserVO loginUserVO= (LoginUserVO) httpSession.getAttribute(Constants.SESSION_KEY);
        log.info("回收站文件删除接收信息:{}",delFileList);
        recycleFileService.delRecycleFile(delFileList,loginUserVO);
        return Result.success();
    }
}
